#For making the interaction graphs...
#Made so it takes the bootstrap output- this is easiest
#Return in a list so you can have the estimates as well
int_plot<-function(model, boot.out, amn, bin){
  list<-list(NA)
  plot.data<-matrix(NA, nrow=3, ncol=4)
  atlist<-list(dummy=c(0,1))
  names(atlist)<-bin
  plot.data[1:2,1]<-summary(margins(model, variable=paste(amn), at=atlist))[,3]
  plot.data[3,1]<-plot.data[2,1]-plot.data[1,1]
  plot.data[,2:3]<-cbind(apply(na.omit(boot.out), 2, sort)[25,], apply(
    na.omit(boot.out),2,sort)[975,])
  plot.data[1,2:3]<-cbind(apply(na.omit(boot.out),2,sort)[50,1], 
                          apply(na.omit(boot.out),2,sort)[950,1])
  plot.data[,4]<-rev(seq(1,3,1))
  plot.data<-as.data.frame(plot.data)
  plot.data[,4]<-factor(plot.data[,4], levels=c(3,2,1),
                        labels=c("Effect of Amnesty Implementation w/o Substitutes",
                                 "Effect of Amnesty Implementation w/ Substitutes",
                                 "Difference"))
  plot.data[,5]<-c(3,2,1)
  colnames(plot.data)<-c("Estimate", "LB", "UB", "Effect", "Dummy")
  
  p<-ggplot(plot.data, aes(y=Estimate, x=reorder(Effect, Dummy)))+
    coord_flip()+
    geom_point(size=3, position=position_dodge(width=.5))+
    geom_linerange(aes(ymin=LB, ymax=UB), position=position_dodge(width=.5))+
    geom_hline(yintercept=0)+
    xlab("")+
    ylab("Marginal Effect of Amnesty on War Recurrence")+
    theme_bw()

  list[[1]]<-p
  list[[2]]<-plot.data
  return(list)
}

